<template>
  <div class="contents">
    <PanelTitle title="适宜性分析" />
    <div class="infoPanel mt">
      <div>
        <div class="infoTitle">土壤</div>
        <div class="infoNums">
          <span class="infoNum">{{ data.soilSuitableType ? '适宜' : '不适宜' }}</span>
        </div>
        <div class="infoSub">{{ data.soilSuitableAnalysis }}</div>
      </div>
      <div>
        <div class="infoTitle">气候</div>
        <div class="infoNums">
          <span class="infoNum">{{ data.airSuitableType ? '适宜' : '不适宜' }}</span>
        </div>
        <div class="infoSub">{{ data.airSuitableAnalysis }}</div>
      </div>
      <div>
        <div class="infoTitle">病虫害</div>
        <div class="infoNums">
          <span class="infoNum">{{ data.wormSuitableType  ? '有' : '无' }}</span>
        </div>
        <div class="infoSub">{{ data.wormSuitableAnalysis }}</div>
      </div>
      <div>
        <div class="infoTitle">极端天气</div>
        <div class="infoNums">
          <img v-for="item in issueList" :src="getImg(item)" @click="toDetail(item)" class="img"  />
          <span v-if="issueList.length == 0" class="infoNum">{{ data.weatherSuitableType  ? '有' : '无' }}</span>
          <!-- <span class="infoNum" v-if="data.weatherSuitableType == null" >无</span>
          <span class="infoNum" v-if="data.weatherSuitableType == 1" >无</span>
          <span class="infoNum" v-if="data.weatherSuitableType == 2" >台风</span>
          <span class="infoNum" v-if="data.weatherSuitableType == 3" >暴雨</span> -->
        </div>
        <!-- <div class="infoSub" :title="data.weatherSuitableAnalysis">{{ data.weatherSuitableAnalysis }}</div> -->
      </div>
    </div>
  </div>
</template>

<script setup>
import http from "@/api/http";
import { env } from "@/utils/env";
import { onMounted, watch, ref } from "vue";
import PanelTitle from "../../component/PanelTitle.vue";
import { useLandStore } from "@/stores/land";
import {getWeather, tencentWeather} from '@/api/weatherApi'
import {weatherImg} from '@/utils/letterUtil'
import { Modal } from 'ant-design-vue';
const landStore = useLandStore()

const data = ref({})
const issueList = ref([])
const getData = async () => {
  let res = await http({
    url: env.VITE_ZHER_DATA_CENTER + "/base/land/suitable/analysis",
    method: "get",
    // params: {landSerialNo : landStore.land.serialNo}, 
  });
  
  if(res.data){
    data.value = res.data
  } else {
    data.value = {}
  }

}

onMounted(async () => {
  getData()

  let res = await tencentWeather('350926')
  if(res.data && res.data.length > 0){
  
    issueList.value = res.data
  }
  // issueList.value = [
  //   {signalType: '台风',signalLevel : '蓝色', issueContent: '台风台风台风' },
  //   {signalType: '暴雪',signalLevel : '蓝色', issueContent: '暴雪暴雪暴雪' },
  //   {signalType: '暴雨',signalLevel : '橙色', issueContent: '暴雨暴雨暴雨' },
  // ]
})
const getImg = (item) => {
    return weatherImg(item.signalType, item.signalLevel)
}
const toDetail = (item) => {
    Modal.warning({
        content: item.issueContent
    })
}
</script>

<style scoped lang="scss">
.contents {
  background: linear-gradient(
    to bottom,
    rgba(5, 79, 99),
    rgba(5, 79, 99, 0.1),
    rgba(5, 79, 99)
  );
  border-radius: vh(8);
  border: vh(1) solid rgba(6, 112, 180, 1);
  .mt {
    margin-top: vh(-40);
  }
}
.infoPanel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: vh(10) vw(15) 0px;

  > div {
    box-sizing: border-box;
    width: vw(160);
    height: vh(80);
    background: rgba(9, 36, 44, 0.4);
    border: vh(1) solid #43e7ff;
    padding: 0 vw(20) 0px;
    margin-bottom: vh(10);
  }
  .infoTitle {
    color: #fff;
    font-size: vh(10);
    line-height: vh(30);
  }
  .infoNums {
    line-height: vh(20);
  }
  .infoNumss {
    line-height: vh(36);
  }
  .infoNum {
    color: #adffd7;
    font-size: vh(26);
    font: SourceHanSansCN-Bold;
  }
  .infoUnit {
    color: #adffd7;
    font-size: vh(16);
    font: SourceHanSansCN-Bold;
    margin-left: vw(4);
  }
  .infoSub {
    padding: 0.5vh 0 0 0;
    font-weight: 400;
    font-size: vh(10);
    color: #adffd7;
    line-height: vh(20);
    white-space: nowrap; /* 确保文本在一行内显示 */
  overflow: hidden; /* 隐藏超出容器的内容 */
  text-overflow: ellipsis;
  }
}

.img{
    width: 60px;
    margin: 0 10px 10px 0;
    cursor: pointer;
  }
</style>